package presentation;

import formatters.*;
import java.rmi.RemoteException;
import java.util.LinkedList;
import java.util.List;
import javax.ejb.CreateException;
import javax.naming.NamingException;
import parsers.InputParser;
import utils.GenericPair;

public class LinkElement extends PresentationElement {
    private List<GenericPair<PresentationElement, Boolean>> externals;
    private String primaryKey;
    public static final String ADD_EXTERNAL = "add-external";
    public static final String GET_EXTERNALS = "get-externals";
    public static final String PRIMARY_KEY = "primary-key";

    public LinkElement() {
        super();
        externals = new LinkedList<GenericPair<PresentationElement, Boolean>>();
    }

    @Override
    public void setParam(String param, Object value) {
        if (param.equals(PRIMARY_KEY)) {
            primaryKey = (String) value;
        } else if (param.equals(ADD_EXTERNAL)) {
            List<Object> list = (List<Object>) value;
            externals.add(new GenericPair((PresentationElement) list.get(0), (Boolean) list.get(1)));
        }
    }

    @Override
    public Object getParam(String param) {
        if (param.equals(PRIMARY_KEY)) {
            return primaryKey;
        }
        if (param.equals(GET_EXTERNALS)) {
            return externals;
        }
        return null;
    }

    @Override
    public void acceptView(ViewFormatter f) {
        f.formatLink(this);
    }

    @Override
    public void acceptEdit(EditFormatter f) {
        f.formatLink(this);
    }

    @Override
    public void acceptInput(InputParser p) {
        p.parseLink(this);
    }

}
